<ui:composition template="/WEB-INF/templates/showcase.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:o="http://omnifaces.org/ui"
>
	<ui:define name="description">
		<p>
			The <code>org.omnifaces.eventlistener.InvokeActionEventListener</code> will add support for new 
			<code>&lt;f:event&gt;</code> types <code>preInvokeAction</code> and <code>postInvokeAction</code>.
			Those events are published during the beforephase and afterphase of <code>INVOKE_APPLICATION</code>
			respectively. This actually offers a better hook on invoking actions after the 
			<code>&lt;f:viewParam&gt;</code> values been set than the <code>preRenderView</code> event. In some 
			circumstances the <code>preRenderView</code> event might be too late. For example, when you need to set a 
			faces message in the flash scope and send a redirect. Also, it won't be invoked when the validations phase
			has failed for one of the <code>&lt;f:viewParam&gt;</code> values, in contrary to the 
			<code>preRenderView</code> event.
		</p>
		<p>
			Note that the upcoming JSF 2.2 will come with a <code>&lt;f:viewAction&gt;</code> tag which should actually
			solve the concrete functional requirement for which a <code>&lt;f:event type="preRenderView"&gt;</code>
			workaround is often been used in JSF 2.0 and 2.1.
		</p>
		<p>
			This event is not only supported on <code>UIViewRoot</code>, but it is also supported on <code>UIForm</code>,
			<code>UIInput</code> and <code>UICommand</code> components. This thus also provides the possibility to invoke
			multiple action listeners on a single <code>UIInput</code> and <code>UICommand</code> component on an easy 
			manner.
		</p>
		<p>			
			As this phase listener has totally no impact on webapp's default behaviour, this phase listener is already 
			registered by OmniFaces own <code>faces-config.xml</code> and thus get auto-initialized when OmniFaces JAR 
			is bundled in webapp, so endusers do not need to register this phase listener explicitly themself.
		</p>
 	</ui:define>		

	<ui:define name="demo">
		<f:view>
			<h3>Replacement for <code>preRenderView</code> event</h3>
			<f:metadata>
				<f:viewParam id="param" name="param" value="#{invokeActionBean.param}" />
				<f:event type="postInvokeAction" listener="#{invokeActionBean.initParam}" />
			</f:metadata>
			<p>
				Clicking <h:link value="this link" outcome="#{view.viewId}?param=test" /> with a "test" request parameter 
				should force a redirect with a faces message in the flash scope which should appear below. This wouldn't
				have worked when <code>preRenderView</code> event is been used.
			</p>
			<p>
				Message: <h:message for="param" />
			</p>

			<h3>Invoking multiple action listeners in <code>UIInput</code> and <code>UICommand</code> components</h3>
			<p>
				Typing in the input field and submitting the below demo form should invoke several action listeners 
				which should each set a global faces message.
			</p>
			<h:form>
				<h:inputText value="#{invokeActionBean.input}">
					<f:ajax event="keyup" execute="@this" listener="#{invokeActionBean.inputListener}" render=":messages" />
					<f:event type="preInvokeAction" listener="#{invokeActionBean.preInvokeAction}" />
					<f:event type="postInvokeAction" listener="#{invokeActionBean.postInvokeAction}" />
				</h:inputText>
				<h:commandButton value="submit" action="#{invokeActionBean.submit}">
					<f:ajax execute="@form" render=":messages" />
					<f:event type="preInvokeAction" listener="#{invokeActionBean.preInvokeAction}" />
					<f:event type="postInvokeAction" listener="#{invokeActionBean.postInvokeAction}" />
				</h:commandButton>
			</h:form>
			<h:messages id="messages" globalOnly="true" />
		</f:view>
	</ui:define>		
</ui:composition>